package homework5

import akka.actor.{Actor, ActorRef}

import java.util.{Timer, TimerTask}

class WorkerActor extends Actor{
  override def receive: Receive = {
    case "注册成功" => {
      println("注册成功了")
    }
    case ("注册", name: String, actorRef: ActorRef, masterActorRef: ActorRef) => {
      masterActorRef ! ("注册", name, actorRef)
    }
    case ("心跳", time: Int, name: String, actorRef: ActorRef, masterActorRef: ActorRef) => {
      println("发送心跳")
      val timer = new Timer()
      timer.schedule(new TimerTask {
        override def run(): Unit = {
          masterActorRef ! ("心跳", name, actorRef)
        }
      },1000,time)
    }
  }
}
